<%-- 
    Document   : addProdManager
    Created on : Feb 28, 2012, 10:34:47 PM
    Author     : frances
--%>

<%@page import="Model.DBConnection"%>
<%@page import="java.sql.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>

        
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="../css/foo.css" type="text/css"></link>
        <link rel="stylesheet" type="text/css" href="../css/superfish.css" media="screen">	
        <title>Foobar</title>
        <script type="text/javascript" src="../js/jquery-1.7.1.min.js"></script>
        <script type="text/javascript" src="../js/hoverIntent.js"></script>
        <script type="text/javascript" src="../js/superfish.js"></script>
        <script type="text/javascript" src="../js/foo.css"></script>
        <script type="text/javascript">

            // initialise plugins
            jQuery(function(){
                jQuery('ul.sf-menu').superfish();
            });
            
            function checkAuth(){
              if(<%=request.getParameter("loginAttempt")%> == false){
                 document.write('<span class="errLog">Authentication failed.</span>');
               }
         }

        </script>
    </head>
    <body class="bg">
        <% if(request.getSession(true).getAttribute("username") == null){ response.sendRedirect("../login.jsp"); } %>
          <script type="text/javascript">checkAuth();</script>
        <br/>
     
        <div class="hmenu">
            <% if (request.getSession(true).getAttribute("username") == null) {%>
           <p style="font-size: 12px; margin-top: -15px; float: right;">If you're not yet a member, sign up <a href="../signUp.jsp">here!</a> </p>   
           <% }%>
           <img src="../images/head.png" style="float: left; margin-left:20px;"></img>
            <div class="log">
                <% if (request.getSession(true).getAttribute("username") != null) {%>
                <h3>Welcome <%=session.getAttribute("username")%>!</h3>
                <br/>
<!--                insert stuff-->
                <a href="../LogoutServlet">Log out</a>
                <% } else {%>
                <span style="font-weight: bold;">Log in</span>
                <form method="post" action="../LoginServlet">
                    <label>Username:</label><input type="text" name="username"/><br/>
                    <label>Password:</label><input type="password" name="password"/><br/>
                    <input type="submit" value="Log in" name="submit"/>
                </form>
                <% }%>
            </div>
                <% if (request.getSession(true).getAttribute("username") != null && session.getAttribute("acctype").equals("admin")){ %>
            <ul class="sf-menu">
                <li class="current">
                <a href="admin.jsp">Home</a>  
                </li>
                <li>
                    <a href="addProdAccnt.jsp">Add Manager</a>
                </li>
                <li>
                    <a href="lockAccount.jsp">Lock/Unlock Account</a>
                </li>
                <li>
                    <a href="viewUserlist.jsp">User List</a>
                    
                </li>
            </ul>
            <%  }else{ %>
             <ul class="sf-menu">
       <li class="current">
                    <a href="index.jsp">Home</a>
                </li>    </li>
                <li>
                    <a href="#">Products</a>
                    <ul>
                        <li>
                            <a href="#">Book</a>
                        </li>
                        <li>
                            <a href="#">Magazine</a>
                        </li>
                        <li>
                            <a href="#">Audio CD</a>
                        </li>
                        <li>
                            <a href="#">DVD</a>
                        </li>
                    </ul>
                </li>
                <li>
                    <a href="#">Stores</a>
                </li>
                <li>
                    <a href="#">Contact Us</a>
                </li>
                <li>
                    <a>SEARCH FUNCTION HERE</a>
                </li>
            </ul>
             <% } %>
        </div>
        <div class="content">
                <% if (request.getSession(true).getAttribute("username") != null && session.getAttribute("acctype").equals("admin")){ %>
            <b>Welcome to Foobar</b>
            <br/>
            Online bookstore made available for you!<br/>
            <hr/>
<!--            <img src="../images/head.png" style="float: left;height: 50px;"></img><br><br>-->
          <p style="font-family: BRITANNIC BOLD; font-size: 20px">Employees and Customers<p>
                    
                 <%
                               Model.DBConnection db = new DBConnection();
                              Connection conn = db.getConnection();

                              Statement stmt = conn.createStatement();  
                              ResultSet rs2 = stmt.executeQuery("Select * from user where UserType = 6 OR UserType = 7 OR UserType = 1 OR UserType = 2 OR UserType = 3 OR UserType = 4");
                              String AccountID = null;
                              String Username = null;
                              //Integer Status = null;
                              %>
                
                              <h4 class="tableForm"><table border="0" cellpadding="3" cellspacing="0" border-radius="5">
                              <tr>
<!--                                  <th align="center" bgcolor="white">Account ID</th>-->
                                  <th align="center" bgcolor="white">Username</th>
                                  <th align="center" bgcolor="white">Status</th>
                              </tr>
                              
                              <% while(rs2.next()){
                                  AccountID = rs2.getString("AccountID");
                                  Username = rs2.getString("Username");
                                 // Integer Status2 = rs2.getInt("Status");
                              %>

                              <tr>
<!--                                  <td WIDTH="45%" bgcolor="silver"><%=AccountID%></td>-->
                                  <td WIDTH="45%" bgcolor="silver"><%=Username%></td>

                                  <%
                                  if(rs2.getInt("Status") == 0){
                                      %>
                                      <form action="../UnlockAccountServlet">
                                      <input type="hidden" value="<%=AccountID%>" name="AccountID"/>
                                      <td WIDTH="45%" bgcolor="silver"> <input type="submit" name="lockaccount" value="Unlock" id="submitButton"> </td>
                                      </form>
                                      <%
                                  } 
                                  else if(rs2.getInt("Status") == 1){
                                  %>
                                      
                                      <form action="../LockAccountServlet">
                                      <input type="hidden" value="<%=AccountID%>" name="AccountID"/>
                                      <td WIDTH="45%" bgcolor="silver"> <input type="submit" name="lockaccount" value="Lock" id="submitButton"> </td>
                                      </form>
                                  
                                  <%
                                   }
                                  %>
                              </tr>
                              
                             <%
                              }
                             %>
   
            <% } else { %>
            <h1>Oops! We don't think you're allowed to be here.</h1>
            <span>Please log in with the correct user credentials</span>
            <% } %>
          </table></h4>
        </div>
    </body>
</html>
